//
//  HJDSetViewController.m
//  JYHospital
//
//  Created by 胡金东 on 16/4/29.
//  Copyright © 2016年 胡金东. All rights reserved.
//

#import "HJDSetViewController.h"
#import "HJDAboutViewController.h"
#import "HJDSuggestViewController.h"
#import "HJDLoginViewController.h"

@interface HJDSetViewController ()<UITableViewDataSource,UITableViewDelegate>
@property(nonatomic,strong)UITableView *tableView;
//@property(nonatomic,strong)UIAlertView *alertExit;
@property(nonatomic,strong)UIButton *exitBtn;

@end

@implementation HJDSetViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor getColorWithHexNumber:@"F1F1EE"];
    self.title = @"设置";
    [self.navigationController.navigationBar setTitleTextAttributes:
     @{NSFontAttributeName:[UIFont systemFontOfSize:19],
       NSForegroundColorAttributeName:[UIColor getColorWithHexNumber:@"848484"]}];

    self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(popToPre) image:@"︿" HighImage:nil];
    
    
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, HJDWidth, 349)];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:self.tableView];
     //清空不用的分割线
    [self clearseparatorline:self.tableView];
    
    self.exitBtn=[[UIButton alloc]initWithFrame:CGRectMake(0,350 , HJDWidth, 45)];
    [self.exitBtn setTitle:@"退出登录" forState:UIControlStateNormal];
    [self.exitBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [self.exitBtn addTarget:self action:@selector(exitClick) forControlEvents:UIControlEventTouchUpInside];
    self.exitBtn.backgroundColor=[UIColor whiteColor];
    [self.view addSubview:self.exitBtn];

   
}
//分割线方法，用view视图盖住footview
-(void)clearseparatorline:(UITableView *)tableView
{
    UIView *view=[[UIView alloc]init];
    view.backgroundColor= [UIColor clearColor];
    [self.tableView setTableFooterView:view];
}

-(void)popToPre
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 3;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    if (section==0) {
        return 3;
    }else if (section ==1){
        return 2;
    }else{
        return 0;
    }
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    UITableViewCell  *cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil];
    
    [ cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
    if (indexPath.section==0) {
        if (indexPath.row==0) {
            cell.textLabel.text=@"当前版本";
             cell.detailTextLabel.text=@"v 1.0.0";
            cell.accessoryType = UITableViewCellAccessoryNone;
//            cell.textLabel.font=[UIFont systemFontOfSize:FONTSIZE_LEVEL2];
           
        }else if (indexPath.row == 1){
            cell.textLabel.text=@"建议反馈";

        }else{
            cell.textLabel.text=@"清除缓存";
            cell.detailTextLabel.text=@"8.8Mb";
        }
    }else if(indexPath.section==1){
        if (indexPath.row==0) {
           cell.textLabel.text = @"分享";
            
        }else{
            cell.textLabel.text=@"关于我们";
        }
    }
    
        return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    if (indexPath.section==0) {
        if (indexPath.row==1) {
            
            HJDSuggestViewController *suggest=[[HJDSuggestViewController alloc]init];
            [self.navigationController pushViewController:suggest animated:YES];
            
        }else if (indexPath.row == 2)
        {
            UIAlertController * alertControl = [UIAlertController alertControllerWithTitle:@"清除缓存" message:nil preferredStyle:UIAlertControllerStyleAlert];
            UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                
            }];
            UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
                
            }];
            
            [alertControl addAction:action];
            [alertControl addAction:cancelAction];
            [self presentViewController:alertControl animated:YES completion:nil];
            
//            UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"清除缓存" message:@"" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
//            [alert show];

        }
    }
   else if (indexPath.section==1) {
        if (indexPath.row==0) {
            
        }else
        {
            HJDAboutViewController *about=[[HJDAboutViewController alloc]init];
            [self.navigationController pushViewController:about animated:YES];

        }
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 2) {
        return 20;
    }else{
        return HJDVerticalMargin;
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 45;
}

-(void)exitClick
{
    UIAlertController * alertControl = [UIAlertController alertControllerWithTitle:@"确定退出？" message:nil preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        HJDLoginViewController *loginVC = [[HJDLoginViewController alloc]init];
        [self presentViewController:loginVC animated:YES completion:nil];
        
    }];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    
    [alertControl addAction:action];
    [alertControl addAction:cancelAction];
    [self presentViewController:alertControl animated:YES completion:nil];
    
}




@end
